<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
echo "<h2>Мнения</h2>";
$this->table->set_heading('id', 'Имя', 'Текст', 'Статус', 'Дата', 'Действия');
$tmpl = array('table_open' => '<table border="0" cellpadding="0" cellspacing="0" class="admin_table">');
$this->table->set_template($tmpl);

$class = 'opinions';
if ($this->users_rights_model->check_rights($class, 'block', true)) $canblock = 1;
if ($this->users_rights_model->check_rights($class, 'unblock', true)) $canblock = 1;
if ($this->users_rights_model->check_rights($class, 'edit', true)) $canedit = 1;
if ($this->users_rights_model->check_rights($class, 'delete', true)) $candelete = 1;
if ($this->users_rights_model->check_rights($class, 'add', true)) $canadd = 1;

$parents[0] = "Новое";
$parents[1] = "Обработаное";

foreach ($pages as $page) {
	$t = nl2br($page['opinion_text']);
	$t2 = nl2br($page['opinion_shop']);
	$text = "";
	if (mb_strlen($t) > 100) {
		$text .= "<div>".mb_substr($t, 0, 100);
			$text .= "<span class='hidden'>".mb_substr($t, 100, mb_strlen($t))."</span>";
		$text .= " <a href='#' class='ajax givememore'>полностью</a></div>";
	} else {
		// $text = "<strong>О товаре</strong><br />".$t;
		// $text .= "<br /><strong>О магазине</strong><br />".$t2;
	}
	$text .= "<br /><a href='#' class='ajax' onClick=\"jQuery('#opinion_".$page['opinion_id']."').toggle(); return false;\">Ответить</a><br />";
	$text .= "<form method='post' action='/admin/opinions/save/".$page['opinion_id']."/?from=".$this->input->get('from')."' style='display: none;' id='opinion_".$page['opinion_id']."'><textarea style='width: 100%; height: 90px;' name='text'>".$page['opinion_answer']."</textarea><br /><a href='#' onClick=\"jQuery(this).parent().submit(); return false;\">Сохранить</a></form>";

	$this->table->add_row(
			array('data' =>$page['opinion_id'], 'style' => ($page['opinion_status'] == '0'?"background: red;":"")),
			array('data' => ($page['opinion_user'] != 0?"<a href='/admin/clients/edit/".$page['opinion_user']."/'>".$page['opinion_name']."</a>":$page['opinion_name'])."<!--<a href='mailto:".$page['opinion_email']."'>".$page['opinion_email']."</a><br />--><br /><a href='".$this->catalog_service_model->get_item_link($page['item_id'])."#opinion_".$page['opinion_id']."' target='_blank'>".$page['item_title']."</a>", 'style' => 'font-size: 11px;'),
			array('data' => $text, 'style' => 'width: 320px; font-size: 11px;'),
			($page['opinion_status'] == '0'?"Новый":"Подтвержден"),
			showmedate($page['opinion_date']),
			array('data' => showmeactions(
					$class,
					$page['opinion_id'],
					$page['opinion_status'],
					0, $candelete, $canblock,
					$from
				), 'style' => 'width: 50px !important;')
		);
}
echo $this->table->generate();
echo $paging;
echo "<div class='cc'></div>";
?>
